package problem.year2023.month01;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author LiangMu
 * @version \$Id: Day03.java, v 0.1, 2023年01月03日 12:42 LiangMu Exp $$
 */
public class Day03 {

    public static void main(String[] args) {
        String s = "hello world 5 x 5";
        System.out.println(areNumbersAscending3(s));
    }

    public static boolean areNumbersAscending(String s) {
        int cur = 0;
        String[] split = s.split(" ");
        for (String it : split) {
            try {
                int i = Integer.parseInt(it);
                if (i <= cur) return false;
                cur = i;
            } catch (NumberFormatException ignored) {
            }
        }
        return true;
    }

    public static boolean areNumbersAscending2(String s) {
        java.util.regex.Pattern compile = java.util.regex.Pattern.compile("\\d+");
        java.util.regex.Matcher matcher = compile.matcher(s);
        int cur = 0;
        while (matcher.find()) {
            String group = matcher.group();
            int i = Integer.parseInt(group);
            if (i <= cur) return false;
            cur = i;
        }
        return true;
    }

    public static boolean areNumbersAscending3(String s) {
        int pre = 0, index = 0;
        while (index < s.length()) {
            if (Character.isDigit(s.charAt(index))) {
                int cur = 0;
                while (index < s.length() && Character.isDigit(s.charAt(index))) {
                    cur = cur * 10 + s.charAt(index) - '0';
                    ++index;
                }
                if (cur <= pre) {
                    return false;
                }
                pre = cur;
            }
            ++index;
        }
        return true;
    }
}
